<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class FLDefaultRecordationAndTransferTaxFactory{

    // FL rules:
    // the default for florida is for the seller to pay taxes on documentary stamp tax on deeds.
    // there is a surcharge of .45 per $100 of consideration when the property being sold is other than a single family home.
    // you should request a check when there is a purchase which states is "check if" (on top) and to the right of box property is a single family home - now,
    // when the answer is yes, you will calculate the tax without the surcharge. if the box is checked, you will calculate the tax at .60/$100 in purchase price,
    // if the box is not checked, you will calculate the transfer tax using 1.05/$100. all of those taxes will default to the seller.
    // you will charge the doc stamp tax on mortgages at .35/$100 plus .002/$1.00 on the loan amount. the default is for the buyer to pay this tax.

    // Implementation notes:
    // .002/$1.00 -> Intangables Tax -> Recordation Tax -> Buyer is default payer
    // .35/$100 ->  CountyPropertyTransferTax -> Buyer is default payer
    // documentary stamp tax on deeds -> StatePropertyTransferTax -> Seller is default payer

    public function createSplitRecordationAndTransferTaxes($propertyTransferTax,
                                                                                $countyPropertyTransferTax,
                                                                                $recordationTax,
                                                                                $extraBuyerRecordationTax,
                                                                                $fees,
                                                                                $payerSpecialCase) {

        $zeroRecordationTax = null;
        if ($recordationTax != null) {
            $zeroRecordationTax = new RecordationTax($recordationTax->getName(), 0.0);
        } else {
            $zeroRecordationTax = null;
        }

        $zeroPropertyTransferTax = null;
        if ($propertyTransferTax != null) {
            $zeroPropertyTransferTax = new StatePropertyTransferTax($propertyTransferTax->getName(), 0.0);
        } else {
            $zeroPropertyTransferTax = null;
        }

        $zeroCountyPropertyTransferTax = null;
        if ($countyPropertyTransferTax != null) {
            $zeroCountyPropertyTransferTax = new CountyPropertyTransferTax($countyPropertyTransferTax->getName(), 0.0);
        } else {
            $zeroCountyPropertyTransferTax = null;
        }

        $recordationAndTransferTaxes = array();

        $zeroFees = FeeHelper::getCloneWithZeroValue($fees);

        // program the application so that, when default is selected, the seller pays all taxes and fees on the deed and
        // the buyer/borrower pays all taxes/fees on the mortgage.
        $buyerFees = array();
        $sellerFees = array();
        if (count($fees) == 2) {
            $sellerFees[] = $fees[0];
            $sellerFees[] = $zeroFees[1];
            $buyerFees[] = $zeroFees[0];
            $buyerFees[] = $fees[1];
        } else {
            if (strpos(strtolower($fees[0]->getName()),"deed") !== FALSE) {
                $sellerFees[0] = $fees[0];
                $buyerFees[0] = $zeroFees[0];
            } else
                if (strpos(strtolower($fees[0]->getName()),"mortgage") !== FALSE) {
                $sellerFees[0] = $zeroFees[0];
                $buyerFees[0] = $fees[0];
            }
        }

        $buyerRecordationTax = null;
        if ($recordationTax != null) {
            $buyerRecordationTax = new RecordationTax($recordationTax->getName(), $recordationTax->getAmount() + $extraBuyerRecordationTax);
        }

        $recordationAndTransferTaxes[0] = new RecordationAndTransferTaxes(
                $zeroPropertyTransferTax,
                $countyPropertyTransferTax,
                $buyerRecordationTax,
                $buyerFees,
                EPayer::Buyer);

        $recordationAndTransferTaxes[1] = new RecordationAndTransferTaxes(
                $propertyTransferTax,
                $zeroCountyPropertyTransferTax,
                $zeroRecordationTax,
                $sellerFees,
                EPayer::Seller);

        return $recordationAndTransferTaxes;
    }
}
?>
